package com.yao.pojo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * 用户在某时刻的收入支出情况
 *
 * @author 妖悲冥
 * @date 2021/5/17 0017   -    11:50
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ManageFinancial {
    private String id;
    private int userId;
    private float amount;
    private String remark;
    private int financialId;
    private Timestamp financialDate;
    private int week = 0;
    private int playId;
    private int moneyId;
    private String date;
    private String time;

    public Date getFinancialDate() {
        if (financialDate != null) {
            return financialDate;
        }
        setFinancialDate();
        return financialDate;
    }

    public void setFinancialDate() {
        //获得util的date
        Date utilDate = null;
        String[] ts = date.replaceAll("[Z]", "").split("T");
        String[] ts1 = time.replaceAll("[Z]", "").split("T");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        try {
            utilDate = format.parse(ts[0] + " " + ts1[1]);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        //日历
        Calendar cal = Calendar.getInstance();
        cal.setTime(utilDate);
        //1-7
        week = cal.get(Calendar.DAY_OF_WEEK);
        //8小时时差
        cal.add(Calendar.HOUR, 8+24);
        //转换为sql的date
        financialDate = new Timestamp(cal.getTime().getTime());
        id = userId + "-" + format.format(cal.getTime());
    }
}
